import myLoading from './index.vue';
import Vue from 'vue';

export default {
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
  install (Vue:any) {
    const Loading = Vue.extend(myLoading);
    const Profile = new Loading({
      el: document.createElement('div')
    });

    const loadingDom = document.querySelector('.load-box') as HTMLElement;

    const myLoadingMethod = {
      show () {
        if (loadingDom === null) {
          document.body.appendChild(Profile.$el);
        }
        Profile.visible = true;
      },
      hide () {
        Profile.visible = false;
      }
    };
    Vue.prototype.$MyLoading = myLoadingMethod;
  }
};

const showLoading = ():void => {
  Vue.prototype.$MyLoading.show();
};
const hideLoading = ():void => {
  Vue.prototype.$MyLoading.hide();
};
export {
  showLoading,
  hideLoading
};
